package nancal.mp.db.mongo.table

import java.io.*
import nbcp.base.db.*
import nbcp.base.comm.*
import nbcp.base.extend.*
import nbcp.base.enums.*
import nbcp.base.utils.*
import nbcp.myoql.db.*
import nbcp.myoql.db.comm.*
import nbcp.myoql.db.enums.*
import nbcp.myoql.db.mongo.*
import nbcp.myoql.db.mongo.base.*
import nbcp.myoql.db.mongo.component.*
import org.slf4j.LoggerFactory
import org.springframework.stereotype.*


@Component("mongo.tenant")
@MetaDataGroup(DatabaseEnum.Mongo, "tenant")
class TenantGroup : IDataGroup {
    override fun getEntities(): Set<BaseMetaData<out Any>> = setOf(tenantLoginUser)


    /**
     * 用户登录表
     */
    val tenantLoginUser get() = TenantLoginUserEntity();


    /**
     * 用户登录表
     */
    @nbcp.base.db.annotation.Cn(value = """用户登录表""")
    @org.springframework.data.mongodb.core.mapping.Document()
    @nbcp.base.db.annotation.DbEntityGroup(value = """tenant""")
    @nbcp.base.db.annotation.DbEntityIndex(value = arrayOf("""id"""), unique = true)
    class TenantLoginUserEntity(collectionName: String = "tenantLoginUser") :
        MongoBaseMetaCollection<nancal.mp.db.mongo.entity.iam.TenantLoginUser>(nancal.mp.db.mongo.entity.iam.TenantLoginUser::class.java, collectionName) {

        val id = MongoColumnName("_id")

        /**
         * 是否可用
         */
        @nbcp.base.db.annotation.Cn(value = """是否可用""") 
        val enabled = MongoColumnName("enabled")

        val tenant = IdNameMeta("tenant")

        /**
         * 登录错误次数
         */
        @nbcp.base.db.annotation.Cn(value = """登录错误次数""") 
        val errorLoginTimes = MongoColumnName("errorLoginTimes")

        /**
         * 是否遗忘密码
         */
        @nbcp.base.db.annotation.Cn(value = """是否遗忘密码""") 
        val forget_password = MongoColumnName("forget_password")

        /**
         * 上次修改密码时间
         */
        @nbcp.base.db.annotation.Cn(value = """上次修改密码时间""") 
        val lastUpdatePwdAt = MongoColumnName("lastUpdatePwdAt")

        /**
         * 是否逻辑删除(false:不删除、true:删除)
         */
        @nbcp.base.db.annotation.Cn(value = """是否逻辑删除(false:不删除、true:删除)""") 
        val isDeleted = MongoColumnName("isDeleted")

        /**
         * 是否第一次登录
         */
        @nbcp.base.db.annotation.Cn(value = """是否第一次登录""") 
        val isFirstLogin = MongoColumnName("isFirstLogin")

        /**
         * 密码的盐
         */
        @nbcp.base.db.annotation.Cn(value = """密码的盐""") 
        val passwordSalt = MongoColumnName("passwordSalt")

        /**
         * 登录名
         */
        @nbcp.base.db.annotation.Cn(value = """登录名""") 
        val loginName = MongoColumnName("loginName")

        /**
         * 登录手机
         */
        @nbcp.base.db.annotation.Cn(value = """登录手机""") 
        val mobile = MongoColumnName("mobile")

        /**
         * 登录邮箱
         */
        @nbcp.base.db.annotation.Cn(value = """登录邮箱""") 
        val email = MongoColumnName("email")

        /**
         * 密码
         */
        @nbcp.base.db.annotation.Cn(value = """密码""") 
        val password = MongoColumnName("password")

        /**
         * 最后登录时间
         */
        @nbcp.base.db.annotation.Cn(value = """最后登录时间""") 
        val lastLoginAt = MongoColumnName("lastLoginAt")

        /**
         * 是否已锁定
         */
        @nbcp.base.db.annotation.Cn(value = """是否已锁定""") 
        val isLocked = MongoColumnName("isLocked")

        /**
         * 锁定详情
         */
        @nbcp.base.db.annotation.Cn(value = """锁定详情""") 
        val lockedRemark = MongoColumnName("lockedRemark")

        /**
         * 创建时间
         */
        @nbcp.base.db.annotation.Cn(value = """创建时间""") 
        val createAt = MongoColumnName("createAt")

        /**
         * 更新时间
         */
        @nbcp.base.db.annotation.Cn(value = """更新时间""") 
        val updateAt = MongoColumnName("updateAt")

        fun queryById(id: String): MongoQueryClip<TenantLoginUserEntity, nancal.mp.db.mongo.entity.iam.TenantLoginUser> {
            return this.query().where { it.id mongoEquals id }
        }


        fun deleteById(id: String): MongoDeleteClip<TenantLoginUserEntity> {
            return this.delete().where { it.id mongoEquals id }
        }

        fun updateById(id: String): MongoUpdateClip<TenantLoginUserEntity, nancal.mp.db.mongo.entity.iam.TenantLoginUser> {
            return this.update().where { it.id mongoEquals id }
        }
        
        

    }

}

